﻿using Newtonsoft.Json;

namespace WholesaleOnline.Controller.Handlers
{
    class HttpAsyncResponse
    {
        private dynamic m_Data = string.Empty;
        public dynamic Data
        {
            set { m_Data = value; }
        }

        private bool m_Success = false;
        public bool Success
        {
            set { m_Success = value; }
        }

        private AjaxResponseType m_Type = AjaxResponseType.Simple;
        public AjaxResponseType Type
        {
            set { m_Type = value; }
        }

        public string ToResponseData()
        {
            dynamic responseData;
            if (m_Type == AjaxResponseType.Simple)
            {
                responseData = new
                {
                    data = m_Data,
                    success = m_Success
                };
            }
            else
            {
                responseData = m_Success ? m_Data : "[]";
            }
            return JsonConvert.SerializeObject(responseData);
        }
    }

    enum AjaxResponseType
    {
        Simple,
        Easyui
    }
}
